package com.adopapa.nezhacloud.outerapi.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.adopapa.nezhacloud.common.RestResponse;
import com.adopapa.nezhacloud.ddd.controller.BaseController;
import com.adopapa.nezhacloud.innerapi.api.InnerLoginService;
import com.adopapa.nezhacloud.outerapi.conf.AppContextUtil;

@RestController
@RequestMapping("api/v1/login")
public class LoginController extends BaseController {

	@Autowired
	private InnerLoginService innerLoginService;


	@GetMapping(path = "/kaptcha.jpg", produces = MediaType.APPLICATION_JSON_VALUE)
	public RestResponse getKaptcha() {
		return innerLoginService.getKaptcha();
	}

	@GetMapping(path = "/auth/{token}", produces = MediaType.APPLICATION_JSON_VALUE)
	public RestResponse auth(@PathVariable String token, String accessUrl) {
		return innerLoginService.auth(token, accessUrl);
	}

	@PostMapping(path = "/login", produces = MediaType.APPLICATION_JSON_VALUE, //
			consumes = MediaType.APPLICATION_JSON_VALUE)
	public RestResponse login(@RequestBody Map<String, String> params) {
		return innerLoginService.login(params);
	}

	@DeleteMapping(path = "/logout", consumes = MediaType.APPLICATION_JSON_VALUE)
	public RestResponse logout() {
		return innerLoginService.logout();
	}

	@PostMapping(path = "/refresh", produces = MediaType.APPLICATION_JSON_VALUE)
	public RestResponse refresh(@RequestHeader String authorization) {
		return innerLoginService.refresh(authorization);
	}

}
